/*******************************************************************************
 * jar名 :  panda-core.jar
 * 文件名 ： GetSpringContext.java
 *       (C) Copyright panda Corporation 2011
 *           All Rights Reserved.
 * *****************************************************************************
 *    注意： 本内容仅限于衮雪公司内部使用，禁止转发
 ******************************************************************************/
package com.panda.common.junit;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;


/**
 * <PRE>
 * 作用:
 *       用来获取在spring文件中定义的bean
 * 限制:
 *       无.
 * 注意事项:
 *       需要在web.xml中配置监听,具体为:
 *       <listener>
 *            <listener-class>com.panda.common.junit.GetSpringContext</listener-class>
 *   	 </listener>
 *       然后在java程序中通过如下方式获得bean对象
 *       WebApplicationContext context = GetSpringContext.getSpringContext();
 *	     TestBean tb = (TestBean) context.getBean("testBean");
 * 修改历史:
 * -----------------------------------------------------------------------------
 *         VERSION       DATE                BY              CHANGE/COMMENT
 * -----------------------------------------------------------------------------
 *          1.0        2011-07-11           null              create
 * -----------------------------------------------------------------------------
 * </PRE>
 */
public class GetSpringContext implements ServletContextListener{

	private static WebApplicationContext springContext; 
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * 获取springContext对象
	 * @return
	 */
	public static WebApplicationContext getSpringContext() {
		return springContext;
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		// TODO Auto-generated method stub
		springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); 
	}

}
